package com.chat.net.socket;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * handler管理者
 */
public class HandlerManager {
    List<ChannelHandler> handlers = new ArrayList<>();

    public void handler(Channel channel) throws IOException, ClassNotFoundException {
            ObjectChannelContext objectChannelContext = (ObjectChannelContext) channel.getChannelContext();
            Object object = objectChannelContext.readObject();
            if(object!=null) {
                for (int i = 0; i < handlers.size(); i++) {
                    ChannelHandler handler = handlers.get(i);
                    handler.handler(channel, object);
                }
            }
    }

    public void addHandler(ChannelHandler channelHandler){
        handlers.add(channelHandler);
    }
}
